/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.ove.openmath.jome.formaters.mml;

/**
 *
 * @author Mr.Sam
 */
import fr.ove.utils.*;
import fr.ove.openmath.jome.model.*;
import fr.ove.openmath.jome.formaters.mml.*;

/**
* Formats the formula tree structure as its corresponding MathML object.<BR>
* This is the formater of the formula root, so returns the formatted representation of the child of
* the instance, enclosed by the <OMOBJ></OMOBJ> pair of tags.
*
* @author © 2000 DIRAT Laurent
* @version 1.0 07/01/2000
*/
public class FormulaFormater implements Formater {
    /**
    * Returns the specified object formatted as a string.
    * @param formatedObject the formatted object (for structured object, could represents the beginning).
    * @param formaterRepository where the different other formaters are.
    * @param obj the object to format.
    */
    public String format(String formatedObject, FormaterRepository formaterRepository, Object obj) {
        if (((FormulaTreeStructure) obj).getNbChildren() != 0) {
            MathMLFormater mmlFormater = (MathMLFormater) formaterRepository;
            mmlFormater.initIndent();
            formatedObject += mmlFormater.writeStartObject();
            
            FormulaTreeStructure ftsChild = (FormulaTreeStructure)((FormulaTreeStructure) obj).getChild(0);
            String objectId = ftsChild.getResourceIdentifier();
            Formater formater = mmlFormater.getFormater(objectId);
            formatedObject = formater.format(formatedObject, mmlFormater, ftsChild);
            
            formatedObject += mmlFormater.writeEndObject();            
        }
        return formatedObject;
    }
}